package homework

object Job3Demo {
  var temp :Tuple4[String,String,Int,Int] = null
  def main(args: Array[String]): Unit = {
    val org="UserA,LocationA,9,60 UserA,LocationA,8,60 UserB,LocationB,10,60 UserB,LocationB,11,80"
    var array: Array[String] =org.split(" ")
    val  tupleArray=array.map(x=>{
     val array2=x.split(",")
      (array2(0),array2(1),array2(2).toInt,array2(3).toInt)
    })
    //排序
    val bx= tupleArray.
      sortBy(r => (r._1, r._2,r._3))( Ordering.Tuple3(Ordering.String, Ordering.String,Ordering.Int) )
    for (a <- bx){
      if (temp==null) temp=a
      else {
      if(temp._1.equals(a._1)&&temp._2.equals(a._2)){
            //时间转化为分钟
            val newTime=a._3*60
            val oldTime=temp._3*60
            if (oldTime+temp._4==newTime){
                temp=(temp._1,temp._2,temp._3,temp._4+a._4)
            }else{
              //名称地点匹配上 但是时间匹配不上
              println(temp)
              temp=a
            }
          }else {
          println(temp)
        temp=a
  }
          //上一个和现在的匹配不上 答应上一个
//          case _ => print(temp)

      }

    }
    println(temp)
  }
}
